/**
 * 
 */
package com.bms.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;

import com.bms.Logic;
import com.bms.abstracts.RESTController;
import com.bms.domain.Event;
import com.bms.domain.Groups;
import com.bms.domain.User;
import com.bms.domain.profile.Profile;

/**
 * @author IBM
 *
 */
public class SummaryController extends RESTController {
	
	private Logic logic;
	
	public void setLogic(Logic logic) {
		this.logic = logic;
	}

	/* (non-Javadoc)
	 * @see com.bms.abstracts.RESTController#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected ModelAndView doGet(HttpServletRequest request,
			HttpServletResponse response) {
		List<Groups> groups = logic.getGroupList();
		request.setAttribute("groups", groups);
		return new ModelAndView("summary");
	}

	/* (non-Javadoc)
	 * @see com.bms.abstracts.RESTController#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected ModelAndView doPost(HttpServletRequest request,
			HttpServletResponse response) {
		String title = request.getParameter("title");
		String createtime = logic.getCurrentDate();
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		String status = request.getParameter("status");
		String summary = request.getParameter("summary");
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		Event event = new Event();
		event.setTitle(title);
		event.setStartTime(startTime);
		event.setEndTime(endTime);
		event.setStatus(status);
		event.setCreatetime(createtime);
		event.setSummary(summary);
		event.setUser(user);
		event.setEventId(Profile.GONG_ZUO_ZONG_JIE);
		logic.addEvent(event);
		return doGet(request,response);
	}

}
